package com.ruoyi.web.controller.his;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.core.domain.model.LoginUser;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.core.redis.RedisCache;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.his.domain.vo.*;
import com.ruoyi.his.service.IHisLargeScreenService;
import com.ruoyi.system.domain.HisLicensedOverWarning;
import com.ruoyi.system.domain.HisVerifyOverdueWarning;
import com.ruoyi.system.service.IHisEngineAnalysisService;
import com.ruoyi.system.service.IHisHospitalNationService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * 大屏接口
 * 
 * @author Alan
 * @date 2024-03-07
 */
@RestController
@RequestMapping("/his/screen")
public class HisLargeScreenController extends BaseController
{
    @Autowired
    private IHisLargeScreenService hisLargeScreenService;
    @Autowired
    private RedisCache redisCache;
    //左边处方就诊统计
    @GetMapping(value = "/analysisResult")
    public AjaxResult getAnalysisResult()
    {
        List<String> hospitalIds =new ArrayList<>();
        List<String> signatures =new ArrayList<>();
        List<Map> mapList = redisCache.getCacheList("hospitalId");
        for (Map map :mapList){
            if(map.get("hospitalId")!=null){
                hospitalIds.add(map.get("hospitalId").toString());
            }
            if(map.get("signature")!=null){
                signatures.add(map.get("signature").toString());
            }
        }
        Map map = hisLargeScreenService.getAnalysisResult(hospitalIds,signatures);
        return AjaxResult.success(map);
    }
    //左边机构处方统计
    @GetMapping(value = "/hospitalNationList")
    public AjaxResult hospitalNationList()
    {
        List<String> hospitalIds =new ArrayList<>();
        List<String> signatures =new ArrayList<>();
        List<Map> mapList = redisCache.getCacheList("hospitalId");
        for (Map map :mapList){
            if(map.get("hospitalId")!=null){
                hospitalIds.add(map.get("hospitalId").toString());
            }
            if(map.get("signature")!=null){
                signatures.add(map.get("signature").toString());
            }
        }
        List<QueryAnalysisDo> list = hisLargeScreenService.hospitalOdsList(hospitalIds,signatures);
        return AjaxResult.success(list);
    }
    //中间今日预警统计
    @GetMapping(value = "/warnList")
    public AjaxResult warnList()
    {
        List<String> hospitalIds =new ArrayList<>();
        List<String> signatures =new ArrayList<>();
        List<Map> mapList = redisCache.getCacheList("hospitalId");
        for (Map map :mapList){
            if(map.get("hospitalId")!=null){
                hospitalIds.add(map.get("hospitalId").toString());
            }
            if(map.get("signature")!=null){
                signatures.add(map.get("signature").toString());
            }
        }
        Map map = hisLargeScreenService.warnList(hospitalIds,signatures);
        return AjaxResult.success(map);
    }
    //中间预警机构明细
    @GetMapping(value = "/toDayWarn")
    public AjaxResult toDayWarn()
    {
        List<String> hospitalIds =new ArrayList<>();
        List<String> signatures =new ArrayList<>();
        List<Map> mapList = redisCache.getCacheList("hospitalId");
        for (Map map :mapList){
            if(map.get("hospitalId")!=null){
                hospitalIds.add(map.get("hospitalId").toString());
            }
            if(map.get("signature")!=null){
                signatures.add(map.get("signature").toString());
            }
        }
        List<Map> map = hisLargeScreenService.toDayWarn(hospitalIds,signatures);
        return AjaxResult.success(map);
    }
    //右边按预警机构统计
    @GetMapping(value = "/getWarnType")
    public AjaxResult getWarnType()
    {
        List<String> hospitalIds =new ArrayList<>();
        List<String> signatures =new ArrayList<>();
        List<Map> mapList = redisCache.getCacheList("hospitalId");
        for (Map map :mapList){
            if(map.get("hospitalId")!=null){
                hospitalIds.add(map.get("hospitalId").toString());
            }
            if(map.get("signature")!=null){
                signatures.add(map.get("signature").toString());
            }
        }
        List<HisHosTypeVo> map = hisLargeScreenService.getWarnType();
        return AjaxResult.success(map);
    }
    //右边按预警类型统计
    @GetMapping(value = "/getWarnTypeNum")
    public AjaxResult getWarnTypeNum(Integer days)
    {
        List<String> hospitalIds =new ArrayList<>();
        List<String> signatures =new ArrayList<>();
        List<Map> mapList = redisCache.getCacheList("hospitalId");
        for (Map map :mapList){
            if(map.get("hospitalId")!=null){
                hospitalIds.add(map.get("hospitalId").toString());
            }
            if(map.get("signature")!=null){
                signatures.add(map.get("signature").toString());
            }
        }
        List<HisLogVo> map = hisLargeScreenService.getWarnTypeNum(days,hospitalIds,signatures);
        return AjaxResult.success(map);
    }


    //中间地图
    @GetMapping(value = "/getMiddleMap")
    public AjaxResult getMiddleMap()
    {
        List<String> hospitalIds =new ArrayList<>();
        List<String> signatures =new ArrayList<>();
        List<Map> mapList = redisCache.getCacheList("hospitalId");
        for (Map map :mapList){
            if(map.get("hospitalId")!=null){
                hospitalIds.add(map.get("hospitalId").toString());
            }
            if(map.get("signature")!=null){
                signatures.add(map.get("signature").toString());
            }
        }
        List<HisDataVo> map = hisLargeScreenService.getMiddleMap(hospitalIds,signatures);
        return AjaxResult.success(map);
    }

    //中间地图
    @GetMapping(value = "/getAdCode")
    public AjaxResult getAdCode()
    {
        Map map = hisLargeScreenService.getAdCode();
        return AjaxResult.success(map);
    }

}
